#include <unistd.h>
#include "lcd_draw.h"
#include "keyboard.h"
#include "tankmove.h"
#include "tank52_60.h"
#include "tank60_52.h"
#include "aiTank_map.h"
#include "gbtest.h"
#include "hzk16.h"
#include "ascii16x8.h"



int main(int argc, char **argv)
{ 
    
    lcd_init();
    kboardInitial();
    draw_map(0, 64);

    int bullet_num;
    bullet_num = 0;
    

    struct tank* lihaotank = tankCreate("lihao", 500, 500);
    struct bullet mybullet[BULLET_NUM];
    tankInitial(lihaotank, gImage_tank52_60);



    showinfor(arcii16x8, hzk16);


    int speed = 1000;

    while(1){
        char input;

        input = kboardInput();
        switch(input){
            case 'w':{
                moveUp(lihaotank, gImage_tank52_60);
                lihaotank->direction = 0;
                printf("input = %c\n", input);
                break;
            }

            case 's':{
                moveDown(lihaotank, gImage_tank52_60);
                lihaotank->direction = 1;
                printf("input = %c\n", input);
                break;
            }
            case 'a':{
                moveLeft(lihaotank, gImage_tank60_52);
                lihaotank->direction = 2;
                printf("input = %c\n", input);
                break;
            }

            case 'd':{
                moveRight(lihaotank, gImage_tank60_52);
                lihaotank->direction = 3;
                printf("input = %c\n", input);
                break;
            }
            case 'j':{
                printf("input = %c\n", input);
                bulletCreate(lihaotank, mybullet, &bullet_num);
                break;
            }
            case '+':{
                printf("speed = %d\n", speed);
                lcd_drawRegionBlack(35, 85, 100, 100);
                if((speed > 25000) || (speed < 1000)){
                    speed = speed;
                }
                else{
                    speed = speed + 1000;
                }
                break;
            }
            case '-':{
                printf("speed = %d\n", speed);
                lcd_drawRegionBlack(35, 85, 100, 100);
                if((speed > 25000) || (speed < 1000)){
                    speed = speed;
                }
                else{
                    speed = speed - 1000;
                }
                break;
            }
            default:{
                break;
            }
        }


        bulletMove(mybullet);
        bulletDestroy(mybullet);
        showSpeed(speed, arcii16x8);
        usleep(speed * 10);

    }
    return 0;
}




